package com.wthink.newMain.msg

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import com.wthink.hzgj.R
import com.wthink.hzgj.databinding.FragmentMsgBinding
import com.wthink.newMain.main.MainNewActivity
import com.wthink.newMain.msg.inner.ReadedFragment
import com.wthink.newMain.msg.inner.UnReadFragment
import com.wthink.newMain.msg.viewmodel.MsgViewmodel

class MsgFragment : Fragment(){
    private val viewModel by viewModels<MsgViewmodel>()

    private lateinit var binding: FragmentMsgBinding

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding = DataBindingUtil.inflate(
            inflater,
            R.layout.fragment_msg,
            container,
            false
        )
        binding.viewModel = viewModel
        binding.lifecycleOwner = this
        return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        activity!!.supportFragmentManager
            .beginTransaction()
            .add(R.id.content,UnReadFragment())
            .commit()

        binding.unreadMsg.isSelected = true
        binding.readedMsg.setOnClickListener {
            addFragment(ReadedFragment())
            binding.readedMsg.isSelected = true
            binding.unreadMsg.isSelected = false

        }

        binding.unreadMsg.setOnClickListener {
            addFragment(UnReadFragment())
            binding.readedMsg.isSelected = false
            binding.unreadMsg.isSelected = true
        }
    }

    private fun addFragment(fragment: Fragment) {
        activity!!.supportFragmentManager
            .beginTransaction()
            //.setCustomAnimations(R.anim.design_bottom_sheet_slide_in, R.anim.design_bottom_sheet_slide_out)
            .replace(R.id.content, fragment, fragment.javaClass.simpleName)
            .commit()
    }

  /*  override fun onResume() {
        super.onResume()
        Log.d("resume", "msgfragmentremuse")
        val mainNewActivity = activity as MainNewActivity
        mainNewActivity.binding.ivSchedle.isSelected = false
        mainNewActivity.binding.ivCamera.isSelected = false
        mainNewActivity.binding.ivServer.isSelected = false
        mainNewActivity.binding.ivBusiness.isSelected = false
        mainNewActivity.binding.ivMsg.isSelected = true
    }

    override fun onDestroyView() {
        super.onDestroyView()
        Log.d("resume", "msgfragmentonDestroyView")
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.d("resume", "msgfragmentonDestroy")
    }*/
}